package com.kudu.api;

import org.apache.kudu.client.*;

public class insertDemo {
    public static void main(String[] args) {
        //1、获取客户端
        KuduClient.KuduClientBuilder builder = new KuduClient.KuduClientBuilder("node51");
        builder.defaultSocketReadTimeoutMs(5000);
        KuduClient client = builder.build();

        try {
            //2、打开一张表
            KuduTable stuTable = client.openTable("student");
            //3、创建会话
            KuduSession kuduSession = client.newSession();
            //4、设置刷数据模式
            kuduSession.setFlushMode(SessionConfiguration.FlushMode.MANUAL_FLUSH);
            //5、获取插入实例
            Insert insert = stuTable.newInsert();
            //6、声明待插入数据
            insert.getRow().addString("id","2");
            insert.getRow().addString("name","lucas");
            insert.getRow().addInt("age",30);
            //7、刷入数据
            kuduSession.flush();
            //8、应用插入实例
            kuduSession.apply(insert);
            //9、关闭会话
            kuduSession.close();
        } catch (KuduException e) {
            e.printStackTrace();
        } finally {
            try {
                client.close();
            } catch (KuduException e) {
                e.printStackTrace();
            }
        }

    }
}
